package examples;

import helpers.EmailHelper;

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.rmi.ServerException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import data.EmailData;
import data.GeoData;
import admin.controllers.SendDealEmailServlet;
import admin.data.PageData;
import admin.data.RoleData;

import debugs.GeoDebug;
import debugs.RoleDebug;

import models.EmailModel;
import models.GeoModel;
import models.PageModel;
import models.RoleModel;

public class CreateExample extends HttpServlet{
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException {
		response.setContentType("text/html");
		//Send email
		Document doc = Jsoup.connect("http://www.onsale365.com.vn/print/dealsemail/preview/RJFU37P5?ModPagespeed=noscript").get();
		String body = doc.html();
		String fromEmail = "onsale365 <khuyenmai@onsale365.com.vn>";
		String toEmail = "hoantocxoan@gmail.com";
		Date date = new Date();
		String subject = "Tiêu đề email gửi vào lúc " + date;
		
		EmailHelper.sendMail(subject, body, fromEmail, toEmail);
		
		response.getWriter().println("<br />");
		response.getWriter().println("send 1 email thanh cong");
		
		//Send many email
		String emails = "hoantocxoan@gmail.com,hoanbn.java@gmail.com";
		String strSubject = "Gửi nhiều email với tiêu đề email gửi vào lúc " + date;
		String strUrl = "http://www.onsale365.com.vn/print/dealsemail/preview/RJFU37P5?ModPagespeed=noscript";
		
		EmailHelper.sendMailFromUrl(fromEmail, strSubject, strUrl, emails);
		
		response.getWriter().println("<br />");
		response.getWriter().println("send nhieu email thanh cong");
		
	}
}
